package com.guoxin.concurrentprogramming.chapter6;

import java.util.stream.IntStream;

/**
 * @author guoxin
 * @date 2019/9/18
 */
public class PrimeUtil {
    public static boolean isPrime(int number) {
        if (number < 2) {
            return false;
        }

        for (int i = 2; Math.sqrt(number) >= i; i++) {
            if (number % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        IntStream.range(1,1000000).filter(PrimeUtil::isPrime).count();
        IntStream.range(1,1000000).parallel().filter(PrimeUtil::isPrime).count();
    }
}
